package teleradiologia.service;

import java.util.List;

import teleradiologia.domain.Customer;
import teleradiologia.domain.Patient;
import teleradiologia.domain.Person;
import teleradiologia.repository.PatientDao;
import teleradiologia.repository.PersonDao;
import teleradiologia.repository.CustomerDao;

public class PatientManipulatorImpl implements PatientManipulator {

	private PatientDao patientDao;
	private PersonDao personDao;
	private CustomerDao customerDao;


	@Override
	public void delete(Patient patient) {
		this.patientDao.delete(patient);
		this.personDao.delete(patient.getPerson());
		this.customerDao.delete(patient.getCustomer());
	}

	@Override
	public Patient getById(long id) {
		return this.patientDao.getById(id);
	}

	@Override
	public void setPatientDao(PatientDao patientDao) {
		this.patientDao = patientDao;
	}

	@Override
	public void update(Patient patient) {
		this.personDao.update(patient.getPerson());
		this.patientDao.update(patient);
	}

	@Override
	public long create(Patient patient, Person person, Customer customer) {
		long idPatient = this.personDao.create(person);
		long idCustomer = this.customerDao.create(customer);

		patient.setPerson(this.personDao.getById(idPatient));
		patient.setCustomer(this.customerDao.getById(idCustomer));

		return this.patientDao.create(patient);
	}

	@Override
	public Patient getByPesel(String pesel) {
		return this.patientDao.getByPesel(pesel);
	}

	public void setPersonDao(PersonDao personDao) {
		this.personDao = personDao;
	}

	public void setCustomerDao(CustomerDao customerDao) {
		this.customerDao = customerDao;
	}

	@Override
	public List<Patient> getAll() {
		return this.patientDao.getAll();
	}

	@Override
	public Patient getByIdPerson(long id) {
		return this.patientDao.getByIdPerson(id);
	}
}
